package com.gxhmplan.talent.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxhmplan.talent.dao.TalentDao;
import com.gxhmplan.talent.entity.Talent;
import com.gxhmplan.talent.service.TalentService;

@Controller
@RequestMapping("")
public class TalentController {
	@Resource
	TalentService talentService;
	@Resource
	TalentDao talentDao;
	@RequestMapping("/talent2.htm")
	public String talent2() {
		return "/WEB-INF/pages/index/talent2.jsp";
	}
	@RequestMapping("/talentAdd.htm")
	public ModelAndView talentAdd(Talent talent) {
		talentService.addTalnet(talent);
		System.out.println(talent);
		return new ModelAndView("redirect:/talent2.htm");
	}
	@RequestMapping("/talent.htm")
	public ModelAndView talent(String id) {
		ModelAndView mav = new ModelAndView("/WEB-INF/pages/show/talent.jsp");
		Talent talent = talentDao.findTalentById(id);
		mav.addObject("talent", talent);
		return mav;
	}
	@RequestMapping("/contactTalent.htm")
	public ModelAndView contactTalent(Integer page) {
		ModelAndView mav = new ModelAndView("/WEB-INF/pages/show/contactTalent.jsp");
		if(null==page || "".equals(page)){page=1;}
		PageHelper.startPage(page, 6);
		List<Map<String,Object>> talentList = talentDao.findTalnet();
		PageInfo<Map<String, Object>> p = new PageInfo<Map<String, Object>>(talentList);
		mav.addObject("talentList", p.getList());
		mav.addObject("total", p.getTotal());
		mav.addObject("pages", p.getPages());
		mav.addObject("pageNum", p.getPageNum());
		mav.addObject("url", "contactTalent.htm");
		return mav;
	}
}
